
/*
 * This is dah Viper debugger...
 */

#include <pthread.h>


bool debugSTOP;
bool debugPAUSE;
bool debugCONT;
bool debugCRASH;
int debugSTREAM;
void backgroundThread();
void listen()
{

	debugSTREAM  = open("debugstream", "w");
	if(debugSTREAM == -1)
		printf("Error: Could not open debug pipe! (are you using a debugger?)\n");
	else
	{
		char* msg = "Viper Debuger";
		pthread_t listener;
		pthread_create(&listener, NULL, backgroundThread, (void*) msg);
		printf("Connected to debugger!\n");
	}
	
}

void backgroundThread()
{
	char* buff = malloc(1);
	char x = 0;
	while(x != 'S')
	{
		read(debugSTREAM,buff,1);
		x = buff[0];
		if(x == 'B') // Break.....
		{
			debugPAUSE = true;
		}
		else if (x == 'C')
		{
			debugPAUSE = false;
		}
		else if (x == 'T')
		{
			printTrace();
		}
		buff[0] = 0;
	}
	// printf("Debugger has disconnected!\n");
	debugSTOP = true;
	close(debugSTREAM);
	unlink("debugstream");
	exit(1);
}
